package game.mapviewer.popups.losses 
{
	import com.rnk.tilelist.TileList;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author rnk
	 */
	public class UnitsTileList 
	{
		private var bg:MovieClip;
		private var tileList:TileList;
		
		public function UnitsTileList(bg:MovieClip) 
		{
			this.bg = bg;
			
		}
		
		public function Init(info:Object,papa:LossesPopup):void
		{
			SetListeners(true);
			
			tileList = new TileList(UnitCell, 6, 1, 0, 40, TileList.SCROLL_VERTICAL, TileList.PAGE_MODE);
			tileList.x = 8;
			tileList.y = 3.75;
			bg.addChild(tileList);
			tileList.mask = bg.tilelistmsk;
			//tileList.smoothScroll = 0.5;
			tileList.data = { papa:papa};
			tileList.dataProvider = info?info.unitsList:null;
			
			
		}
		
		private function SetListeners(orly:Boolean):void 
		{
			if (orly)
			{
				bg.scrollbar.scrollup.addEventListener(MouseEvent.CLICK, OnButtonClicked);
				bg.scrollbar.scrolldown.addEventListener(MouseEvent.CLICK, OnButtonClicked);
			} else
			{
				bg.scrollbar.scrollup.removeEventListener(MouseEvent.CLICK, OnButtonClicked);
				bg.scrollbar.scrolldown.removeEventListener(MouseEvent.CLICK, OnButtonClicked);
			}
		}
		
		private function OnButtonClicked(e:MouseEvent):void 
		{
			switch (e.target) 
			{
				case bg.scrollbar.scrollup:
					tileList.PrevPage();
				break;
				case bg.scrollbar.scrolldown:
					tileList.NextPage();
				break;
			}
		}
		
		public function Die():void
		{
			SetListeners(false);
		}
		
		
	}

}